<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title> 冯宝宝送水后台管理系统</title>
    <link rel="icon" href="https://jscdn.com.cn/highcharts/images/favicon.ico">

    <!--Bootstrap固定框架-->
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap-theme.css}">
    <!--图标库-->
    <link rel='stylesheet' th:href='@{/css/material-design-iconic-font.min.css}'>
    <!--核心样式-->
    <link rel="stylesheet" th:href="@{/css/style.css}">

    <script th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>

    <style>
        .myWorkerImage{
            width:40px;
            height:40px;
        }
        #add,#sub{
            font-size:20px;
            color:red;
            font-weight: bold;
        }
    </style>
    <script>
        //为送水工加工资 一次加500
        $(function () {
            //为 “+” 绑定点击事件
            $("span[id=add]").click(function () {
                //获取送回ID
                let workerid = $(this).attr("class");
                //选择 + 下一个元素，获取送水工的构造
                let workerSalary = $(this).next().text()
                //计算调整之后的工资
                workerSalary = parseInt(workerSalary);
                workerSalary += 500;
                //将工资设置到页面
                $(this).next().text(workerSalary);
                //使用ajax技术向后端发起调整工资的异步请求
                $.ajax({
                    //请求的URL
                    url:'/worker/addSalary',
                    //提交给后端服务
                    data:{
                        wid:workerid,
                        workerSalary:workerSalary,
                    },
                    //请求方式
                    method:"POST",
                    //请求成功后的回调函数
                    success:function (data,status) {
                        if (data == "OK"){
                            alert("调整工资成功");
                        }else {
                            alert("调整工资失败");
                        }
                    }
                })

            })
        })

        //为送水工减工资 一次键500  sub
        $(function () {
            //为 “-” 绑定点击事件
            $("span[id=sub]").click(function () {
                //获取送回ID
                let workerid = $(this).attr("class");
                //选择 - 上个元素，获取送水工的工资
                let workerSalary = $(this).prev().text()
                //计算调整之后的工资
                workerSalary = parseInt(workerSalary);
                workerSalary -= 500;
                //将工资设置到页面
                $(this).prev().text(workerSalary);
                //使用ajax技术向后端发起调整工资的异步请求
                $.ajax({
                    //请求的URL
                    url:'/worker/addSalary',
                    //提交给后端服务
                    data:{
                        wid:workerid,
                        workerSalary:workerSalary,
                    },
                    //请求方式
                    method:"POST",
                    //请求成功后的回调函数
                    success:function (data,status) {
                        if (data == "OK"){
                            alert("调整工资成功");
                        }else {
                            alert("调整工资失败");
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>

<div id="viewport">

    <!-- Sidebar
    客户列表页面使用th:replace属性替换成主菜单的侧边栏，让代码能够复用
    th:replace="waterMainMenu::sidebar"
    waterMainMenu表示主菜单页面的文件名称
    sidebar表示主菜单页面的片段名称
    -->
    <div id="sidebar" th:replace="waterMainMenu::sidebar">

    </div>

    <!-- Content -->
    <div id="content">
        <!--
th:replace="waterMainMenu::navbar"表示将nav标签里面所有的内容替换为主页面的navbar片段
        -->
        <nav class="navbar navbar-default" th:replace="waterMainMenu::navbar">

        </nav>

        <div class="container-fluid">
            <div class="row">

                <div class="col-md-12">
                    <div class="col-md-4" style="left: -1%">
                        <!--添加按钮-->
                        <a class="btn btn-info"
                           th:href="@{/worker/preSaveWorker}">添加送水工信息</a>
                        <a class="btn btn-success" th:href="@{/hello}">回到首页</a>
                    </div>
                </div>

                <div class="col-md-8" style="margin-left: 77.5%">
                    <form class="form-inline" th:action="@{/worker/workerList}">
                        <div class="form-group">
                            <label for="searchName">送水工名称：</label>
                            <input type="text" class="form-control" th:value="${workerName}" th:name="workerName" id="searchName" placeholder="请输入送水工名称">
                        </div>
                        <button type="submit" class="btn btn-primary">查询</button>
                    </form>
                </div>



                <div class="col-md-12" style="margin-top: 15px">
                    <table class="table table-bordered table-hover" border="1px">
                        <thead>
                        <tr class="success" style="text-align: center">
                            <td>送水工编号</td>
                            <td>送水工名称</td>
                            <td>送水工底薪</td>
                            <td>送水工提成</td>
                            <td>送水工照片</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="worker : ${pageInfo.list}" style="text-align: center">
                            <td th:text="${worker.wid}"></td>
                            <td th:text="${worker.workerName}"></td>
                            <!--                            <td th:text="${worker.workerSalary}"></td>-->
                            <td>
                                <span id="add" th:class="${worker.wid}">+</span>
                                <span id="salary" th:text="${worker.workerSalary}"></span>
                                <span id="sub" th:class="${worker.wid}">-</span>
                            </td>
                            <td th:text="${worker.workerMoney}"></td>

                            <td>
                                <!--没有上传图像显示系统默认的图像
                                  th:if="${#strings.isEmpty(worker.workerImage)}"
                                  条件成立：表示没有上传图像，显示默认的图像
                                -->
                                <img class="myWorkerImage"
                                     th:if="${#strings.isEmpty(worker.workerImage)}"
                                     src="/img/lxc.png" />
                                <!--条件成立：表示用户上传了图片，显示在服务器上显示上传图片-->
                                <img class="myWorkerImage"
                                     th:if="${not #strings.isEmpty(worker.workerImage)}"
                                     th:src="'http://112.74.114.93:8088/'+${worker.workerImage}"/>
                            </td>

                            <td>
                                <a class="btn btn-warning"
                                   th:href="@{'/worker/preUpdateWorker/'+${worker.wid}}">修改</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!--显示分页信息部分代码-->
            <div class="modal-footer no-margin-top">
                <div class="col-md-6">
                    <strong>
                        当前第<span style="color: red"> [[${pageInfo.pageNum}]]</span>页
                        共 <span style="color: red">[[${pageInfo.pages}]] </span> 页
                        一共<span style="color: red"> [[${pageInfo.total}]]</span> 条记录
                    </strong>
                </div>
                <ul class="pagination pull-right no-margin">

                    <!--hasPreviousPage 是否有前一页-->
                    <li th:if="${pageInfo.hasPreviousPage}">
                        <a th:href="'/worker/workerList?pageNum=1'">首页</a>
                    </li>

                    <li class="prev" th:if="${pageInfo.hasPreviousPage}">
                        <!--prePage:前一页-->
                        <a th:href="'/worker/workerList?pageNum='+${pageInfo.prePage}">
                            <i class="ace-icon fa fa-angle-double-left"></i>
                            <span>&laquo;</span>
                        </a>
                    </li>

                    <!--遍历条数-->
                    <!--navigatepageNums：所有导航页号-->
                    <li th:each="nav:${pageInfo.navigatepageNums}">
                        <a th:href="'/worker/workerList?pageNum='+${nav}" th:text="${nav}" th:if="${nav != pageInfo.pageNum}"></a>
                        <span style="font-weight: bold;background: #6faed9;" th:if="${nav == pageInfo.pageNum}" th:text="${nav}" ></span>
                    </li>

                    <!--hasNextPage：是否有下一页-->
                    <li class="next" th:if="${pageInfo.hasNextPage}">
                        <a th:href="'/worker/workerList?pageNum='+${pageInfo.nextPage}">
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>

                    <li>
                        <a th:href="'/worker/workerList?pageNum='+${pageInfo.pages}">尾页</a>
                    </li>
                </ul>
            </div>


        </div>
    </div>

</div>

</body>
</html>